﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Reflection;
using System.ComponentModel;

namespace LuWeibo
{
    public class Theme : DependencyObject
    {
        static Theme()
        {
            if (!DesignerProperties.IsInDesignTool)
            {
                RedTheme.BaseBrush = new SolidColorBrush(Colors.Red);
                GreenTheme.BaseBrush = new SolidColorBrush(Colors.Green);
                BlueTheme.BaseBrush = new SolidColorBrush(Colors.Blue);
                BlackTheme.BaseBrush = new SolidColorBrush(Colors.Black);
            }
            TurnBlack();
        }

        private static Theme CurrentTheme = new Theme();
        private static Theme RedTheme = new Theme();
        private static Theme GreenTheme = new Theme();
        private static Theme BlueTheme = new Theme();
        private static Theme BlackTheme = new Theme();

        public static Theme Instance
        {
            get
            {
                return CurrentTheme;
            }
        }

        #region Dependency Properties
        public Brush BaseBrush
        {
            get { return (Brush)GetValue(BaseBrushProperty); }
            set { SetValue(BaseBrushProperty, value); }
        }

        public static readonly DependencyProperty BaseBrushProperty =
            DependencyProperty.Register("BaseBrush", typeof(Brush), typeof(Theme), new PropertyMetadata(new SolidColorBrush(Colors.Black),null));

        #endregion

        #region Method
        /// <summary>
        /// 复制样式
        /// </summary>
        /// <param name="theme"></param>
        public void Copy(Theme theme)
        {
            MemberInfo[] memberInfos = theme.GetType().GetMembers();
            foreach (var memberInfo in memberInfos)
            {
                if (memberInfo is PropertyInfo)
                {
                    PropertyInfo propertyInfo = (PropertyInfo)memberInfo;
                    if (propertyInfo.CanWrite)
                    {
                        propertyInfo.SetValue(this, propertyInfo.GetValue(theme, null), null);
                    }
                }
            }
        }
        /// <summary>
        /// 变红
        /// </summary>
        public static void TurnRed()
        {
            CurrentTheme.Copy(RedTheme);
        }
        /// <summary>
        /// 变绿
        /// </summary>
        public static void TurnGreen()
        {
            CurrentTheme.Copy(GreenTheme);
        }

        public static void TurnBlue()
        {
            CurrentTheme.Copy(BlueTheme);
        }

        public static void TurnBlack()
        {
            CurrentTheme.Copy(BlackTheme);
        }
        #endregion

        
    }
}
